package com.xueyi.aixihu.entity.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @author LuQi
 * @类描述
 * @时间 2021/11/17
 */
@Data
@AllArgsConstructor
public class WxMessageVo {

    private String touser;
    private String template_id;
    private String url;
    private String lang = "zh_CN";
    private Map<String, TemplateParam> data;

    public WxMessageVo build(String touser, String template_id, String page) {

        if (StringUtils.isEmpty(template_id) || StringUtils.isEmpty(touser)) {
            throw new RuntimeException("openId 或者 template_id");
        }

        this.touser = touser;
        this.template_id = template_id;
        this.url = page;
        return this;
    }

    public WxMessageVo setData(Map<String, TemplateParam> data) {
        if (CollectionUtils.isEmpty(data)) {
            throw new RuntimeException("data 数据为空");
        }
        this.data = data;
        return this;
    }

    public WxMessageVo() {
    }

    public WxMessageVo(String touser, String template_id, String page) {
        this.touser = touser;
        this.template_id = template_id;
        this.url = page;
    }

    public WxMessageVo buildSmallEntity(String xcxPage) {

        if (!StringUtils.isEmpty(xcxPage)) {
            this.url = "";
        }
        return this;
    }
}
